package com.ultrapower.request;

import java.util.List;

import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Scan;

import com.ultrapower.bean.SpanBean;
import com.ultrapower.mapper.SpanMapperV2;
import com.ultrapower.util.HBaseTables;
import com.ultrapower.util.TransactionId;
import com.ultrapower.util.rowkey.TraceRowKeyDecoderV2;
import com.ultrapower.util.rowkey.TraceRowKeyEncoderV2;
/**
 * 
 * @author wangy
 *
 */
public class TraceV2Table extends BaseRequest {
	TraceRowKeyEncoderV2 rowKeyEncoder = new TraceRowKeyEncoderV2(null);
	TraceRowKeyDecoderV2 rowKeyDecoder = new TraceRowKeyDecoderV2();

	public static void main(String[] args) {
		BaseRequest table = new TraceV2Table();
		table.execute();
	}

	@Override
	void execute() {
		TableName traceTableName = this.getTableName(HBaseTables.TRACE_V2_STR);
		this.getHbaseTemplate().get(traceTableName, getRowKey(), HBaseTables.TRACE_V2_CF_SPAN, null, result -> {
			SpanMapperV2 map = new SpanMapperV2(rowKeyDecoder);
			List<SpanBean> list = map.mapRow(result, 0);
			if (list == null || list.isEmpty()) {
				System.out.println("空数据");
				return null;
			}
			list.forEach(c -> {
				System.out.println(c);
			});
			return null;
		});
	}

	@Override
	protected Scan createScan() {
		return null;
	}

	protected byte[] getRowKey() {
		long transactionSequence = 3060;
		long startTime = 1532681287546L;
		TransactionId transactionId = new TransactionId(agentId,startTime, transactionSequence);
		return rowKeyEncoder.encodeRowKey(transactionId);
	}
}
